*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*	Uses the b matrix left behind by olsvam to create a variable storing the
*	yearly VAM of the enrolled school. Useful when we want an OLS-VAM unaffected
*	by student exposures, e.g. when binning offers.
*
*	OPTIONS
*		d - varlist of endogenous variables
*		gen - variable encoding the yearly-VAM of the enrolled school
*	----------------------------------------------------------------------------

	program define schvam, rclass
	cap program drop schvam
	syntax name, d(varlist) gen(name) [vgen(name)]

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	cap mat b = r(b)
	if _rc!=0{
		di as error "previous olsvam estimates not found."
		exit()
	}
	gen `gen' = .
	foreach var of varlist `d'{
		tokenize "`var'", parse("_")
		local sch = `3'
		cap replace `gen' = b[1,"`var'"] if sch == `sch'
	}
	di "schvam: variable `gen' generated"
	if "`vgen'"!=""{
		mat V = r(V)
		gen `vgen' = .
		foreach var of varlist `d'{
			tokenize "`var'", parse("_")
			local sch = `3'
			cap replace `vgen' = V["`var'","`var'"] if sch == `sch'
		}
		di "schvam: variable `vgen' generated"
	}

	end
